
import './styles/style.css'
import { createApp,defineComponent  } from 'vue';
import App from './App.vue';
import router from './router';
import { useAppStore, useAuthStore, useUserStore } from './store';
import { setupStore } from "./store";
import { createAuth0 } from '@auth0/auth0-vue';
import auth0Config from './auth0Config';
import 'virtual:uno.css'

const app = createApp(App);

const auth0 = createAuth0(auth0Config);
app.use(auth0);

app.use(router);
setupStore(app);

const appStore = useAppStore();
const authStore = useAuthStore();
const userStore = useUserStore();


app.provide('appStore', appStore);
app.provide('authStore', authStore);
app.provide('userStore', userStore);

router.beforeEach((to, from, next) => {
    if (to.matched.some(record => record.meta.requireAuth)) {
      if (!app.config.globalProperties.$auth0.isAuthenticated) {
        next({ path: '/' });
      } else {
        next();
      }
    } else {
      next();
    }
  });

app.mount('#app');